﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using iLangl.Model;
using iLangl.Customer.DAL;

namespace iLangl.Customer.DNN
{
	public class TranslationManager
	{
		#region Singelton Pattern
		private static TranslationManager instance;
		private static object mutex = new object();
		/// <summary>
		/// The instance of the TranslationManager.
		/// </summary>
		public static TranslationManager Instance
		{
			get
			{
				if (instance == null)
				{
					lock (mutex)
					{
						if (instance == null)
						{
							instance = new TranslationManager();

						}
					}
				}
				return instance;
			}
		}
		#endregion

		public Translation[] FindTranslations(
			String sourceCustomerIdentity,
			String targetCustomerIdentity,
			String sourceLanguageCode,
			String targetLanguageCode)
		{
			Translation[] translations = DALFacade.Instance.TranslationDAL.ReadTranslations
				(
				sourceCustomerIdentity,
				targetCustomerIdentity,
				sourceLanguageCode,
				targetLanguageCode
				);

			foreach (Translation translation in translations)
			{
				translation.Project = DALFacade.Instance.ProjectDAL.ReadProject(translation.Project.Id);
			}

			return translations;
		}
	}
}